home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / HENSA / MATHS / PLPLOT / PLPLOT.ZIP / src / plpage.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-25  |  7.0 KB  |  270 lines

  1. /* $Id: plpage.c,v 1.11 1994/08/25 04:10:03 mjl Exp $
  2.  * $Log: plpage.c,v $
  3.  * Revision 1.11  1994/08/25  04:10:03  mjl
  4.  * Moved plClrCWindows() out of pladv() into plP_eop(), to ensure it always
  5.  * gets called at the end of a page.  Put in handling for insufficient
  6.  * remaining space in windows struct.
  7.  *
  8.  * Revision 1.10  1994/07/29  20:27:40  mjl
  9.  * Added plGetCursor() and other support routines for returning the cursor
  10.  * location in world coordinates given a mouse click, if supported by the
  11.  * driver.  Supports multiple windows per page, and gets the correct set
  12.  * of world coordinates for the plot selected.  Contributed by Paul Casteels.
  13.  *
  14.  * Revision 1.9  1994/06/30  18:27:17  mjl
  15.  * All core source files: made another pass to eliminate warnings when using
  16.  * gcc -Wall.  Lots of cleaning up: got rid of includes of math.h or string.h
  17.  * (now included by plplot.h), and other minor changes.  Now each file has
  18.  * global access to the plstream pointer via extern; many accessor functions
  19.  * eliminated as a result.  Subpage initialization code moved to this file --
  20.  * subpage settings can now be changed any time (previously, it had to be
  21.  * done before calling plinit).
  22. */
  23.  
  24. /*    plpage.c
  25.  
  26.     Page/subpage handling routines
  27. */
  28.  
  29. #include "plplotP.h"
  30.  
  31. /* Page window list. */
  32.  
  33. int nrCWindows = 0;
  34. CWindow windows[PL_MAXWINDOWS];
  35.  
  36. /*----------------------------------------------------------------------*\
  37.  * void pladv()
  38.  *
  39.  * Advance to subpage "page", or to the next one if "page" = 0.
  40. \*----------------------------------------------------------------------*/
  41.  
  42. void
  43. c_pladv(PLINT page)
  44. {
  45.     if (plsc->level < 1) {
  46.     plabort("pladv: Please call plinit first");
  47.     return;
  48.     }
  49.  
  50.     if (page > 0 && page <= plsc->nsubx * plsc->nsuby)
  51.     plsc->cursub = page;
  52.  
  53.     else if (page == 0) {
  54.     if (plsc->cursub >= plsc->nsubx * plsc->nsuby) {
  55.         plP_eop();
  56.         plP_bop();
  57.         plsc->cursub = 1;
  58.     }
  59.     else
  60.         plsc->cursub++;
  61.     }
  62.     else {
  63.     plabort("pladv: Invalid subpage number");
  64.     return;
  65.     }
  66.  
  67.     plP_setsub();
  68. }
  69.  
  70. /*----------------------------------------------------------------------*\
  71.  * void pleop()
  72.  *
  73.  * End current page.
  74. \*----------------------------------------------------------------------*/
  75.  
  76. void
  77. c_pleop(void)
  78. {
  79.     if (plsc->level < 1) {
  80.     plabort("pleop: Please call plinit first");
  81.     return;
  82.     }
  83.  
  84.     plsc->cursub = plsc->nsubx * plsc->nsuby;
  85.     plP_eop();
  86. }
  87.  
  88. /*----------------------------------------------------------------------*\
  89.  * void plbop()
  90.  *
  91.  * Start new page.  Should only be used with pleop().
  92. \*----------------------------------------------------------------------*/
  93.  
  94. void
  95. c_plbop(void)
  96. {
  97.     if (plsc->level < 1) {
  98.     plabort("pladv: Please call plinit first");
  99.     return;
  100.     }
  101.     plP_bop();
  102.     plsc->cursub = 1;
  103.     plP_setsub();
  104. }
  105.  
  106. /*----------------------------------------------------------------------*\
  107.  * void plP_subpInit()
  108.  *
  109.  * Set up plot parameters according to the number of subpages.
  110. \*----------------------------------------------------------------------*/
  111.  
  112. void
  113. plP_subpInit(void)
  114. {
  115.     PLFLT gscale, hscale;
  116.     PLFLT size_chr, size_sym, size_maj, size_min;
  117.  
  118. /* Subpage checks */
  119.  
  120.     if (plsc->nsubx <= 0)
  121.     plsc->nsubx = 1;
  122.     if (plsc->nsuby <= 0)
  123.     plsc->nsuby = 1;
  124.  
  125. /* Force a page advance */
  126.  
  127.     plP_eop();
  128.     plP_bop();
  129.     plsc->cursub = 0;
  130.  
  131. /*
  132.  * Set default sizes
  133.  * Global scaling:
  134.  *    Normalize to the page length for more uniform results.
  135.  *     A virtual page length of 200 mm is assumed.
  136.  * Subpage scaling:
  137.  *    Reduce sizes with plot area (non-proportional, so that character
  138.  *    size doesn't get too small).
  139.  */
  140.     gscale = 0.5 *
  141.     ((plsc->phyxma - plsc->phyxmi) / plsc->xpmm +
  142.      (plsc->phyyma - plsc->phyymi) / plsc->ypmm) / 200.0;
  143.  
  144.     hscale = gscale / sqrt((double) plsc->nsuby);
  145.  
  146.     size_chr = 4.0;
  147.     size_sym = 4.0;        /* All these in virtual plot units */
  148.     size_maj = 3.0;
  149.     size_min = 1.5;
  150.  
  151.     plsc->chrdef = plsc->chrht = size_chr * hscale;
  152.     plsc->symdef = plsc->symht = size_sym * hscale;
  153.     plsc->majdef = plsc->majht = size_maj * hscale;
  154.     plsc->mindef = plsc->minht = size_min * hscale;
  155. }
  156.  
  157. /*----------------------------------------------------------------------*\
  158.  * void plP_setsub()
  159.  *
  160.  * Set up the subpage boundaries according to the current subpage selected.
  161. \*----------------------------------------------------------------------*/
  162.  
  163. void
  164. plP_setsub(void)
  165. {
  166.     PLINT ix, iy;
  167.  
  168.     ix = (plsc->cursub - 1) % plsc->nsubx;
  169.     iy = plsc->nsuby - (plsc->cursub - 1) / plsc->nsubx;
  170.  
  171.     plsc->spdxmi = (PLFLT) (ix)     / (PLFLT) (plsc->nsubx);
  172.     plsc->spdxma = (PLFLT) (ix + 1) / (PLFLT) (plsc->nsubx);
  173.     plsc->spdymi = (PLFLT) (iy - 1) / (PLFLT) (plsc->nsuby);
  174.     plsc->spdyma = (PLFLT) (iy)     / (PLFLT) (plsc->nsuby);
  175.  
  176.     plsc->sppxmi = plP_dcpcx(plsc->spdxmi);
  177.     plsc->sppxma = plP_dcpcx(plsc->spdxma);
  178.     plsc->sppymi = plP_dcpcy(plsc->spdymi);
  179.     plsc->sppyma = plP_dcpcy(plsc->spdyma);
  180.  
  181.     plP_sclp(plsc->sppxmi, plsc->sppxma, plsc->sppymi, plsc->sppyma);
  182. }
  183.  
  184. /*----------------------------------------------------------------------*\
  185.  * void plgspa()
  186.  *
  187.  * Get subpage boundaries in absolute coordinates (mm from bottom
  188.  * left-hand corner of page.
  189. \*----------------------------------------------------------------------*/
  190.  
  191. void
  192. c_plgspa(PLFLT *xmin, PLFLT *xmax, PLFLT *ymin, PLFLT *ymax)
  193. {
  194.     if (plsc->level < 1) {
  195.     plabort("plgspa: Please call plinit first");
  196.     return;
  197.     }
  198.     *xmin = plP_dcmmx(plsc->spdxmi);
  199.     *xmax = plP_dcmmx(plsc->spdxma);
  200.     *ymin = plP_dcmmy(plsc->spdymi);
  201.     *ymax = plP_dcmmy(plsc->spdyma);
  202. }
  203.  
  204. /*----------------------------------------------------------------------*\
  205.  * int plGetCursor()
  206.  *
  207.  * Wait for right button mouse event and translate to world coordinates.
  208.  * Returns 0 if no translation to world coordinates is possible.  
  209.  * Written by Paul Casteels.
  210. \*----------------------------------------------------------------------*/
  211.  
  212. int
  213. plGetCursor(PLCursor *cursor) 
  214. {
  215.     int i;
  216.     CWindow *w;
  217.  
  218.     plP_esc(PLESC_GETC, cursor);
  219.     cursor->wX = 0;
  220.     cursor->wY = 0;
  221.     for (i = 0; i < nrCWindows; i++) {
  222.     w = &windows[i];
  223.     if ((cursor->vpX > w->vpx1) &&
  224.         (cursor->vpX < w->vpx2) &&
  225.         (cursor->vpY > w->vpy1) &&
  226.         (cursor->vpY < w->vpy2) ) {
  227.  
  228.         cursor->wX = w->wx1 +
  229.         (cursor->vpX - w->vpx1) * (w->wx2 - w->wx1) / 
  230.             (w->vpx2 - w->vpx1);
  231.  
  232.         cursor->wY = w->wy1 +
  233.         (cursor->vpY - w->vpy1) * (w->wy2 - w->wy1) / 
  234.             (w->vpy2 - w->vpy1);
  235.  
  236.         return 1;
  237.     }
  238.     }
  239.     return 0;
  240. }
  241.  
  242. /*----------------------------------------------------------------------*\
  243.  * void plAddCWindow()
  244.  *
  245.  * Adds a window to the window list (called by plwind).  
  246.  * Written by Paul Casteels.
  247. \*----------------------------------------------------------------------*/
  248.  
  249. void 
  250. plAddCWindow(CWindow window) 
  251. {
  252.     if (nrCWindows >= PL_MAXWINDOWS)
  253.     return;
  254.  
  255.     windows[nrCWindows++] = window;
  256. }
  257.  
  258. /*----------------------------------------------------------------------*\
  259.  * void plClrCWindows()
  260.  *
  261.  * Resets all known windows (called by plP_eop).
  262.  * Written by Paul Casteels.
  263. \*----------------------------------------------------------------------*/
  264.  
  265. void 
  266. plClrCWindows(void) 
  267. {
  268.     nrCWindows = 0;
  269. }
  270.